package me.zhengjie.business.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.zhengjie.business.domain.vo.*;
import me.zhengjie.business.repository.LargeScreenRepository;
import me.zhengjie.business.repository.ZhsqRepository;
import me.zhengjie.business.service.HomeService;
import me.zhengjie.business.service.LargeScreenService;
import me.zhengjie.config.DebugProperties;
import me.zhengjie.utils.DateTimeUtil;
import me.zhengjie.utils.PageUtil;
import me.zhengjie.utils.StringUtils;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @website https://el-admin.vip
 * @description 首页查询
 * @author xiahongbo
 * @date 2022-10-15
 **/
@Slf4j
@Service
@RequiredArgsConstructor
public class LargeScreenServiceImpl implements LargeScreenService {

    private final LargeScreenRepository largeScreenRepository;

    /**
     * 每月各区申请人数（柱形图）
     * @param starttime
     * @param endtime
     * @return
     */
    @Override
    public JSONObject queryLeft1(String starttime, String endtime, String zhlb) {

        endtime = StringUtils.isEmpty(endtime) ? DateTimeUtil.getDateTime() : endtime;
        starttime = StringUtils.isEmpty(starttime) ? DateTimeUtil.getDateTime(DateTimeUtil.getMonthFirstDay(DateTimeUtil.addMonths(DateTimeUtil.parse(endtime, DateTimeUtil.DEFAULT_DATE_FORMAT), -5)), DateTimeUtil.DEFAULT_DATE_FORMAT) : starttime;

        JSONArray timeArray = new JSONArray();
        Date startDate = DateTimeUtil.parse(starttime, DateTimeUtil.DEFAULT_DATE_FORMAT);
        Date endDate = DateTimeUtil.parse(endtime, DateTimeUtil.DEFAULT_DATE_FORMAT);
        int diffMon = DateTimeUtil.diffMonths(endDate, startDate);
        timeArray.add(DateTimeUtil.getDateTime(startDate, "yyyy-MM"));
        Date tempDate = startDate;
        for (int i = 0; i < diffMon; i++) {
            tempDate = DateTimeUtil.addMonths(tempDate, 1);
            timeArray.add(DateTimeUtil.getDateTime(tempDate, "yyyy-MM"));
        }

        for (int i = 0; i < timeArray.size(); i++) {

            System.out.println("timeArray tempDate:"+timeArray.getString(i));
        }

        JSONArray ccsCodeArray = new JSONArray();
        ccsCodeArray.add("220102");
        ccsCodeArray.add("220103");
        ccsCodeArray.add("220104");
        ccsCodeArray.add("220105");
        ccsCodeArray.add("220106");
        ccsCodeArray.add("220107");
        ccsCodeArray.add("220108");
        ccsCodeArray.add("220109");
        ccsCodeArray.add("220110");
        ccsCodeArray.add("220176");
        ccsCodeArray.add("220199");
        JSONArray ccsNameArray = new JSONArray();
        ccsNameArray.add("南关");
        ccsNameArray.add("宽城");
        ccsNameArray.add("朝阳");
        ccsNameArray.add("二道");
        ccsNameArray.add("绿园");
        ccsNameArray.add("经开");
        ccsNameArray.add("净月");
        ccsNameArray.add("高新");
        ccsNameArray.add("汽开");
        ccsNameArray.add("北湖");
        ccsNameArray.add("莲花山");

        JSONArray cnt220102 = new JSONArray();
        JSONArray cnt220103 = new JSONArray();
        JSONArray cnt220104 = new JSONArray();
        JSONArray cnt220105 = new JSONArray();
        JSONArray cnt220106 = new JSONArray();
        JSONArray cnt220107 = new JSONArray();
        JSONArray cnt220108 = new JSONArray();
        JSONArray cnt220109 = new JSONArray();
        JSONArray cnt220110 = new JSONArray();
        JSONArray cnt220176 = new JSONArray();
        JSONArray cnt220199 = new JSONArray();
        log.info("starttime:{},endtime:{},zhlb:{}", starttime, endtime, zhlb);
        List<Object> list = largeScreenRepository.queryLeft1(starttime, endtime, zhlb);
        for (int i = 0; i < list.size(); i++) {
            Object o = list.get(i);
            Object[] arr = (Object[]) o;

            Object ssxq = arr[0];
            Object yf = arr[1];
            Object sl = arr[2];
/*            cnt220102.add(i, 0);
            cnt220103.add(i, 0);
            cnt220104.add(i, 0);
            cnt220105.add(i, 0);
            cnt220106.add(i, 0);
            cnt220107.add(i, 0);
            cnt220108.add(i, 0);
            cnt220109.add(i, 0);
            cnt220110.add(i, 0);
            cnt220176.add(i, 0);
            cnt220199.add(i, 0);*/
            for (int j = 0; j < timeArray.size(); j++) {
                if(ccsCodeArray.getString(0).equals(ssxq) && yf.equals(timeArray.getString(j))){
                    System.out.println("yf:"+yf+"|timeArray.getString(j)"+timeArray.getString(j));
                    cnt220102.set(j, sl);
                }
                if(ccsCodeArray.getString(1).equals(ssxq) && yf.equals(timeArray.getString(j))){
                    cnt220103.set(j, sl);
                }
                if(ccsCodeArray.getString(2).equals(ssxq) && yf.equals(timeArray.getString(j))){
                    cnt220104.set(j, sl);
                }
                if(ccsCodeArray.getString(3).equals(ssxq) && yf.equals(timeArray.getString(j))){
                    cnt220105.set(j, sl);
                }
                if(ccsCodeArray.getString(4).equals(ssxq) && yf.equals(timeArray.getString(j))){
                    cnt220106.set(j, sl);
                }
                if(ccsCodeArray.getString(5).equals(ssxq) && yf.equals(timeArray.getString(j))){
                    cnt220107.set(j, sl);
                }
                if(ccsCodeArray.getString(6).equals(ssxq) && yf.equals(timeArray.getString(j))){
                    cnt220108.set(j, sl);
                }
                if(ccsCodeArray.getString(7).equals(ssxq) && yf.equals(timeArray.getString(j))){
                    cnt220109.set(j, sl);
                }
                if(ccsCodeArray.getString(8).equals(ssxq) && yf.equals(timeArray.getString(j))){
                    cnt220110.set(j, sl);
                }
                if(ccsCodeArray.getString(9).equals(ssxq) && yf.equals(timeArray.getString(j))){
                    cnt220176.set(j, sl);
                }
                if(ccsCodeArray.getString(10).equals(ssxq) && yf.equals(timeArray.getString(j))){
                    cnt220199.set(j, sl);
                }
            }

        }
/*
        for (int j = 0; j < timeArray.size(); j++) {
            String yf = timeArray.getString(j);

            List<Object> list = largeScreenRepository.queryLeft11(yf, zhlb);
            if(list.size() != 0) {

                for (int i = 0; i < list.size(); i++) {
                    Object o = list.get(i);
                    Object[] arr = (Object[]) o;

                    Object ssxq = arr[0];
                    Object sl = arr[2];

                    cnt220102.add(i, "0");
                    cnt220103.add(i, "0");
                    cnt220104.add(i, "0");
                    cnt220105.add(i, "0");
                    cnt220106.add(i, "0");
                    cnt220107.add(i, "0");
                    cnt220108.add(i, "0");
                    cnt220109.add(i, "0");
                    cnt220110.add(i, "0");
                    cnt220176.add(i, "0");
                    cnt220199.add(i, "0");
                    if(ccsCodeArray.getString(0).equals(ssxq)){
                        cnt220102.set(j, sl);
                    }
                    if(ccsCodeArray.getString(1).equals(ssxq)){
                        cnt220103.set(j, sl);
                    }
                    if(ccsCodeArray.getString(2).equals(ssxq)){
                        cnt220104.set(j, sl);
                    }
                    if(ccsCodeArray.getString(3).equals(ssxq)){
                        cnt220105.set(j, sl);
                    }
                    if(ccsCodeArray.getString(4).equals(ssxq)){
                        cnt220106.set(j, sl);
                    }
                    if(ccsCodeArray.getString(5).equals(ssxq)){
                        cnt220107.set(j, sl);
                    }
                    if(ccsCodeArray.getString(6).equals(ssxq)){
                        cnt220108.set(j, sl);
                    }
                    if(ccsCodeArray.getString(7).equals(ssxq)){
                        cnt220109.set(j, sl);
                    }
                    if(ccsCodeArray.getString(8).equals(ssxq)){
                        cnt220110.set(j, sl);
                    }
                    if(ccsCodeArray.getString(9).equals(ssxq)){
                        cnt220176.set(j, sl);
                    }
                    if(ccsCodeArray.getString(10).equals(ssxq)){
                        cnt220199.set(j, sl);
                    }
                }
            } else {
                cnt220102.add("0");
                cnt220103.add("0");
                cnt220104.add("0");
                cnt220105.add("0");
                cnt220106.add("0");
                cnt220107.add("0");
                cnt220108.add("0");
                cnt220109.add("0");
                cnt220110.add("0");
                cnt220176.add("0");
                cnt220199.add("0");
            }
        }
        */
        log.info("cnt220102:{}", cnt220102);

        JSONObject obj = new JSONObject();
        obj.put("cnt220102", cnt220102);
        obj.put("cnt220103", cnt220103);
        obj.put("cnt220104", cnt220104);
        obj.put("cnt220105", cnt220105);
        obj.put("cnt220106", cnt220106);
        obj.put("cnt220107", cnt220107);
        obj.put("cnt220108", cnt220108);
        obj.put("cnt220109", cnt220109);
        obj.put("cnt220110", cnt220110);
        obj.put("cnt220176", cnt220176);
        obj.put("cnt220199", cnt220199);
        obj.put("ccsCodeArray", ccsCodeArray);
        obj.put("timeArray", timeArray);
        return obj;
    }

    /**
     * 每月申请人数（饼形图）
     * @param starttime
     * @param endtime
     * @return
     */
    @Override
    public JSONObject queryLeft2(String starttime, String endtime, String zhlb) {
        endtime = StringUtils.isEmpty(endtime) ? DateTimeUtil.getDateTime() : endtime;
        starttime = StringUtils.isEmpty(starttime) ? DateTimeUtil.getDateTime(DateTimeUtil.getMonthFirstDay(DateTimeUtil.addMonths(DateTimeUtil.parse(endtime, DateTimeUtil.DEFAULT_DATE_FORMAT), -5)), DateTimeUtil.DEFAULT_DATE_FORMAT) : starttime;

        JSONArray pie1Array = new JSONArray();
        List<Object> listPie1 = largeScreenRepository.queryLeft2(starttime, endtime, zhlb);
        for (int i = 0; i < listPie1.size(); i++) {
            JSONObject obj = new JSONObject();
            Object o = listPie1.get(i);
            Object[] arr = (Object[]) o;

            obj.put("name", arr[0]);
            obj.put("value", arr[1]);
            pie1Array.add(obj);
        }
        JSONObject obj = new JSONObject();
        obj.put("pie1Array", pie1Array);
        return obj;
    }

    /**
     * 每月职工、居民的申请人数(环形图)
     * @param starttime
     * @param endtime
     * @return
     */
    @Override
    public JSONObject queryLeft3(String starttime, String endtime, String zhlb) {
        endtime = StringUtils.isEmpty(endtime) ? DateTimeUtil.getDateTime() : endtime;
        starttime = StringUtils.isEmpty(starttime) ? DateTimeUtil.getDateTime(DateTimeUtil.getMonthFirstDay(DateTimeUtil.addMonths(DateTimeUtil.parse(endtime, DateTimeUtil.DEFAULT_DATE_FORMAT), -5)), DateTimeUtil.DEFAULT_DATE_FORMAT) : starttime;

        JSONArray pie1Array = new JSONArray();
        List<Object> listPie1 = largeScreenRepository.queryLeft2(starttime, endtime, zhlb);
        for (int i = 0; i < listPie1.size(); i++) {
            JSONObject obj = new JSONObject();
            Object o = listPie1.get(i);
            Object[] arr = (Object[]) o;

            obj.put("name", arr[0]);
            obj.put("value", arr[1]);
            pie1Array.add(obj);
        }
        JSONArray pie2Array = new JSONArray();
        List<Object> listPie2 = largeScreenRepository.queryLeft3(starttime, endtime, zhlb);
        for (int i = 0; i < listPie2.size(); i++) {
            JSONObject obj = new JSONObject();
            Object o = listPie2.get(i);
            Object[] arr = (Object[]) o;

            obj.put("name", arr[1]);
            obj.put("value", arr[2]);
            pie2Array.add(obj);
        }
        JSONObject obj = new JSONObject();
        obj.put("pie1Array", pie1Array);
        obj.put("pie2Array", pie2Array);
        return obj;
    }

    /**
     * 每月已签约人数(柱形图)
     * @param starttime
     * @param endtime
     * @return
     */
    @Override
    public JSONObject queryLeft4(String starttime, String endtime, String zhlb) {
        endtime = StringUtils.isEmpty(endtime) ? DateTimeUtil.getDateTime() : endtime;
        starttime = StringUtils.isEmpty(starttime) ? DateTimeUtil.getDateTime(DateTimeUtil.getMonthFirstDay(DateTimeUtil.addMonths(DateTimeUtil.parse(endtime, DateTimeUtil.DEFAULT_DATE_FORMAT), -5)), DateTimeUtil.DEFAULT_DATE_FORMAT) : starttime;

        JSONArray monthArray = new JSONArray();
        JSONArray dataArray = new JSONArray();
        List<Object> qylist = largeScreenRepository.queryLeft4(starttime, endtime, zhlb);
        for (int i = 0; i < qylist.size(); i++) {
            Object o = qylist.get(i);
            Object[] arr = (Object[]) o;

            dataArray.add(arr[1]);
            monthArray.add(arr[2]);
        }
        JSONObject obj = new JSONObject();
        obj.put("monthArray", monthArray);
        obj.put("dataArray", dataArray);
        return obj;
    }


    /**
     * 每月已服务人数(柱形图)
     * @param starttime
     * @param endtime
     * @return
     */
    @Override
    public JSONObject queryLeft5(String starttime, String endtime, String zhlb) {
        endtime = StringUtils.isEmpty(endtime) ? DateTimeUtil.getDateTime() : endtime;
        starttime = StringUtils.isEmpty(starttime) ? DateTimeUtil.getDateTime(DateTimeUtil.getMonthFirstDay(DateTimeUtil.addMonths(DateTimeUtil.parse(endtime, DateTimeUtil.DEFAULT_DATE_FORMAT), -5)), DateTimeUtil.DEFAULT_DATE_FORMAT) : starttime;

        JSONArray monthArray = new JSONArray();
        JSONArray dataArray = new JSONArray();
        List<Object> fwrslist = largeScreenRepository.queryLeft5(starttime, endtime, zhlb);
        for (int i = 0; i < fwrslist.size(); i++) {
            Object o = fwrslist.get(i);
            Object[] arr = (Object[]) o;

            dataArray.add(arr[1]);
            monthArray.add(arr[2]);
        }
        JSONObject obj = new JSONObject();
        obj.put("monthArray", monthArray);
        obj.put("dataArray", dataArray);
        return obj;
    }

    /**
     * 每月已服务人次(条形图)
     * @param starttime
     * @param endtime
     * @return
     */
    @Override
    public JSONObject queryCenter3(String starttime, String endtime, String zhlb) {
        endtime = StringUtils.isEmpty(endtime) ? DateTimeUtil.getDateTime() : endtime;
        starttime = StringUtils.isEmpty(starttime) ? DateTimeUtil.getDateTime(DateTimeUtil.getMonthFirstDay(DateTimeUtil.addMonths(DateTimeUtil.parse(endtime, DateTimeUtil.DEFAULT_DATE_FORMAT), -5)), DateTimeUtil.DEFAULT_DATE_FORMAT) : starttime;

        endtime = endtime.substring(0, 10);

        JSONArray monthArray = new JSONArray();
        JSONArray dataArray = new JSONArray();
        if("03".equals(zhlb)) {
            List<Object> fwrclist = largeScreenRepository.queryCenter3(starttime, endtime, zhlb);
            for (int i = 0; i < fwrclist.size(); i++) {
                Object o = fwrclist.get(i);
                Object[] arr = (Object[]) o;

                dataArray.add(arr[1]);
                monthArray.add(arr[2]);
            }
        } else {
            List<Object> fwrclist = largeScreenRepository.queryCenter31(starttime, endtime, zhlb);
            for (int i = 0; i < fwrclist.size(); i++) {
                Object o = fwrclist.get(i);
                Object[] arr = (Object[]) o;

                dataArray.add(arr[1]);
                monthArray.add(arr[2]);
            }
        }
        JSONObject obj = new JSONObject();
        obj.put("monthArray", monthArray);
        obj.put("dataArray", dataArray);
        return obj;
    }

    /**
     * 每月评估人数(饼形图)
     * @param starttime
     * @param endtime
     * @return
     */
    @Override
    public JSONObject queryRigth1(String starttime, String endtime, String zhlb) {

        endtime = StringUtils.isEmpty(endtime) ? DateTimeUtil.getDateTime() : endtime;
        starttime = StringUtils.isEmpty(starttime) ? DateTimeUtil.getDateTime(DateTimeUtil.getMonthFirstDay(DateTimeUtil.addMonths(DateTimeUtil.parse(endtime, DateTimeUtil.DEFAULT_DATE_FORMAT), -5)), DateTimeUtil.DEFAULT_DATE_FORMAT) : starttime;

        JSONArray pie1Array = new JSONArray();
        List<Object> list = largeScreenRepository.queryRigth1(starttime, endtime, zhlb);
        for (int i = 0; i < list.size(); i++) {
            JSONObject obj = new JSONObject();
            Object o = list.get(i);
            Object[] arr = (Object[]) o;

            obj.put("name", arr[0]);
            obj.put("value", arr[1]);
            pie1Array.add(obj);
        }
        JSONObject obj = new JSONObject();
        obj.put("pieArray", pie1Array);
        return obj;
    }

    /**
     * 每月复核人数(饼形图)
     * @param starttime
     * @param endtime
     * @return
     */
    @Override
    public JSONObject queryRigth2(String starttime, String endtime, String zhlb) {

        endtime = StringUtils.isEmpty(endtime) ? DateTimeUtil.getDateTime() : endtime;
        starttime = StringUtils.isEmpty(starttime) ? DateTimeUtil.getDateTime(DateTimeUtil.getMonthFirstDay(DateTimeUtil.addMonths(DateTimeUtil.parse(endtime, DateTimeUtil.DEFAULT_DATE_FORMAT), -5)), DateTimeUtil.DEFAULT_DATE_FORMAT) : starttime;

        JSONArray pie1Array = new JSONArray();
        List<Object> list = largeScreenRepository.queryRigth2(starttime, endtime, zhlb);
        for (int i = 0; i < list.size(); i++) {
            JSONObject obj = new JSONObject();
            Object o = list.get(i);
            Object[] arr = (Object[]) o;

            obj.put("name", arr[0]);
            obj.put("value", arr[1]);
            pie1Array.add(obj);
        }
        JSONObject obj = new JSONObject();
        obj.put("pieArray", pie1Array);
        return obj;
    }

    /**
     * 机构已享受待遇各失能等级人员数量(饼形图)
     * @param starttime
     * @param endtime
     * @return
     */
    @Override
    public JSONObject queryRigth3(String starttime, String endtime, String zhlb) {

        endtime = StringUtils.isEmpty(endtime) ? DateTimeUtil.getDateTime() : endtime;
        starttime = StringUtils.isEmpty(starttime) ? DateTimeUtil.getDateTime(DateTimeUtil.getMonthFirstDay(DateTimeUtil.addMonths(DateTimeUtil.parse(endtime, DateTimeUtil.DEFAULT_DATE_FORMAT), -5)), DateTimeUtil.DEFAULT_DATE_FORMAT) : starttime;

        JSONArray pie1Array = new JSONArray();
        JSONArray legendNameArray = new JSONArray();
        List<Object> list = largeScreenRepository.queryRigth3(zhlb);
        for (int i = 0; i < list.size(); i++) {
            JSONObject obj = new JSONObject();
            Object o = list.get(i);
            Object[] arr = (Object[]) o;

            obj.put("name", arr[0]);
            obj.put("value", arr[1]);
            pie1Array.add(obj);
            legendNameArray.add(arr[0]);
        }
        JSONObject obj = new JSONObject();
        obj.put("pieArray", pie1Array);
        obj.put("legendNameArray", legendNameArray);
        return obj;
    }

    /**
     * 机构已享受待遇各参保类型人员数量(饼形图)
     * @param starttime
     * @param endtime
     * @return
     */
    @Override
    public JSONObject queryRigth4(String starttime, String endtime, String zhlb) {

        endtime = StringUtils.isEmpty(endtime) ? DateTimeUtil.getDateTime() : endtime;
        starttime = StringUtils.isEmpty(starttime) ? DateTimeUtil.getDateTime(DateTimeUtil.getMonthFirstDay(DateTimeUtil.addMonths(DateTimeUtil.parse(endtime, DateTimeUtil.DEFAULT_DATE_FORMAT), -5)), DateTimeUtil.DEFAULT_DATE_FORMAT) : starttime;

        JSONArray pie1Array = new JSONArray();
        JSONArray legendNameArray = new JSONArray();
        List<Object> list = largeScreenRepository.queryRigth4(zhlb);
        for (int i = 0; i < list.size(); i++) {
            JSONObject obj = new JSONObject();
            Object o = list.get(i);
            Object[] arr = (Object[]) o;

            obj.put("name", arr[0]);
            obj.put("value", arr[1]);
            pie1Array.add(obj);
            legendNameArray.add(arr[0]);
        }
        JSONObject obj = new JSONObject();
        obj.put("pieArray", pie1Array);
        obj.put("legendNameArray", legendNameArray);
        return obj;
    }

    /**
     * 居家已享受待遇各参保类型人员数量(饼形图)
     * @param starttime
     * @param endtime
     * @return
     */
    @Override
    public JSONObject queryRigth44(String starttime, String endtime) {
        endtime = StringUtils.isEmpty(endtime) ? DateTimeUtil.getDateTime() : endtime;
        starttime = StringUtils.isEmpty(starttime) ? DateTimeUtil.getDateTime(DateTimeUtil.getMonthFirstDay(DateTimeUtil.addMonths(DateTimeUtil.parse(endtime, DateTimeUtil.DEFAULT_DATE_FORMAT), -5)), DateTimeUtil.DEFAULT_DATE_FORMAT) : starttime;

        endtime = endtime.substring(0, 10);

        JSONArray pie1Array = new JSONArray();
        JSONArray legendNameArray = new JSONArray();
        List<Object> list = largeScreenRepository.queryRigth44(starttime, endtime);
        for (int i = 0; i < list.size(); i++) {
            JSONObject obj = new JSONObject();
            Object o = list.get(i);
            Object[] arr = (Object[]) o;

            obj.put("name", arr[0]);
            obj.put("value", arr[1]);
            pie1Array.add(obj);
            legendNameArray.add(arr[0]);
        }
        JSONObject obj = new JSONObject();
        obj.put("pieArray", pie1Array);
        obj.put("legendNameArray", legendNameArray);
        return obj;
    }

    @Override
    public JSONObject queryRigth5(String starttime, String endtime, String zhlb) {

        endtime = StringUtils.isEmpty(endtime) ? DateTimeUtil.getDateTime() : endtime;
        starttime = StringUtils.isEmpty(starttime) ? DateTimeUtil.getDateTime(DateTimeUtil.getMonthFirstDay(DateTimeUtil.addMonths(DateTimeUtil.parse(endtime, DateTimeUtil.DEFAULT_DATE_FORMAT), -5)), DateTimeUtil.DEFAULT_DATE_FORMAT) : starttime;

        JSONArray timeArray = new JSONArray();
        Date startDate = DateTimeUtil.parse(starttime, DateTimeUtil.DEFAULT_DATE_FORMAT);
        Date endDate = DateTimeUtil.parse(endtime, DateTimeUtil.DEFAULT_DATE_FORMAT);
        int diffMon = DateTimeUtil.diffMonths(endDate, startDate);
        timeArray.add(DateTimeUtil.getDateTime(startDate, "yyyy-MM"));
        Date tempDate = startDate;
        for (int i = 0; i < diffMon; i++) {
            tempDate = DateTimeUtil.addMonths(tempDate, 1);
            timeArray.add(DateTimeUtil.getDateTime(tempDate, "yyyy-MM"));
        }

        // 申请人数
        JSONArray sqrsArray = new JSONArray();
        List<Object> sqrslist = largeScreenRepository.queryLeft2(starttime, endtime, zhlb);
        for (int i = 0; i < sqrslist.size(); i++) {
            Object o = sqrslist.get(i);
            Object[] arr = (Object[]) o;
            sqrsArray.add(arr[1]);
        }

        // 评估人数
        JSONArray pgrsArray = new JSONArray();
        List<Object> pgrslist = largeScreenRepository.queryRigth1(starttime, endtime, zhlb);
        for (int i = 0; i < pgrslist.size(); i++) {
            Object o = pgrslist.get(i);
            Object[] arr = (Object[]) o;
            pgrsArray.add(arr[1]);
        }

        // 复核人数
        JSONArray fhrsArray = new JSONArray();
        List<Object> fhrslist = largeScreenRepository.queryRigth2(starttime, endtime, zhlb);
        for (int i = 0; i < fhrslist.size(); i++) {
            Object o = fhrslist.get(i);
            Object[] arr = (Object[]) o;

            fhrsArray.add(arr[1]);
        }

        // 签约人数
        JSONArray qyrsArray = new JSONArray();
        List<Object> qyrslist = largeScreenRepository.queryLeft4(starttime, endtime, zhlb);
        for (int i = 0; i < qyrslist.size(); i++) {
            Object o = qyrslist.get(i);
            Object[] arr = (Object[]) o;

            qyrsArray.add(arr[1]);
        }

        // 服务人数
        JSONArray fwrsArray = new JSONArray();
        List<Object> fwrslist = largeScreenRepository.queryLeft5(starttime, endtime, zhlb);
        for (int i = 0; i < fwrslist.size(); i++) {
            Object o = fwrslist.get(i);
            Object[] arr = (Object[]) o;

            fwrsArray.add(arr[1]);
        }
        JSONObject obj = new JSONObject();
        obj.put("sqrsArray", sqrsArray);
        obj.put("pgrsArray", pgrsArray);
        obj.put("fhrsArray", fhrsArray);
        obj.put("qyrsArray", qyrsArray);
        obj.put("fwrsArray", fwrsArray);
        obj.put("timeArray", timeArray);

        log.info("queryRigth5: {}", obj);
        return obj;
    }

    /**
     * 概况
     * @param starttime /
     * @param endtime /
     * @return /
     */
    @Override
    public JSONObject queryTop(String starttime, String endtime, String zhlb) {

        endtime = StringUtils.isEmpty(endtime) ? DateTimeUtil.getDateTime() : endtime;
        starttime = StringUtils.isEmpty(starttime) ? DateTimeUtil.getDateTime(DateTimeUtil.getMonthFirstDay(DateTimeUtil.addMonths(DateTimeUtil.parse(endtime, DateTimeUtil.DEFAULT_DATE_FORMAT), -5)), DateTimeUtil.DEFAULT_DATE_FORMAT) : starttime;

        List<Object> list = largeScreenRepository.queryTop(starttime, endtime, zhlb);
        JSONObject obj = new JSONObject();
        for (int i = 0; i < list.size(); i++) {
            Object o = list.get(i);
            Object[] arr = (Object[]) o;

            obj.put("sqrs", arr[0]);
            obj.put("pgrs", arr[1]);
            obj.put("fhrs", arr[2]);
            obj.put("qyrs", arr[3]);
            obj.put("fwrs", arr[4]);
            obj.put("fwrc", arr[5]);
            obj.put("jgrc", arr[6]);
        }
        return obj;
    }

    /**
     * 查询居家
     * @param jg /
     * @return /
     */
    @Override
    public JSONArray queryHomeGs(String jg) {
        List<Object> list = largeScreenRepository.queryHomeGs(jg);
        JSONArray rsarray = new JSONArray();
        for (int i = 0; i < list.size(); i++) {
            Object o = list.get(i);
            Object[] arr = (Object[]) o;

            JSONObject object = new JSONObject();
            JSONArray array = new JSONArray();

            array.add(arr[3]);
            array.add(arr[4]);
            object.put("name", arr[1]);
            object.put("bm", arr[2]);
            object.put("value", array);
            rsarray.add(object);
        }
        return rsarray;
    }

    /**
     * 查询机构
     * @param jg /
     * @return /
     */
    @Override
    public JSONArray queryOrgGs(String jg) {
        List<Object> list = largeScreenRepository.queryOrgGs(jg);
        JSONArray rsarray = new JSONArray();
        for (int i = 0; i < list.size(); i++) {
            Object o = list.get(i);
            Object[] arr = (Object[]) o;

            JSONObject object = new JSONObject();
            JSONArray array = new JSONArray();

            array.add(arr[3]);
            array.add(arr[4]);
            object.put("name", arr[1]);
            object.put("bm", arr[2]);
            object.put("value", array);
            rsarray.add(object);
        }
        return rsarray;
    }

    @Override
    public JSONObject queryAmount(String starttime, String endtime, String zhlb) {
        endtime = StringUtils.isEmpty(endtime) ? DateTimeUtil.getDateTime() : endtime;
        starttime = StringUtils.isEmpty(starttime) ? DateTimeUtil.getDateTime(DateTimeUtil.getMonthFirstDay(DateTimeUtil.addMonths(DateTimeUtil.parse(endtime, DateTimeUtil.DEFAULT_DATE_FORMAT), -5)), DateTimeUtil.DEFAULT_DATE_FORMAT) : starttime;

        JSONArray timeArray = new JSONArray();
        Date startDate = DateTimeUtil.parse(starttime, DateTimeUtil.DEFAULT_DATE_FORMAT);
        Date endDate = DateTimeUtil.parse(endtime, DateTimeUtil.DEFAULT_DATE_FORMAT);
        int diffMon = DateTimeUtil.diffMonths(endDate, startDate);
        timeArray.add(DateTimeUtil.getDateTime(startDate, "yyyy-MM"));
        Date tempDate = startDate;
        for (int i = 0; i < diffMon; i++) {
            tempDate = DateTimeUtil.addMonths(tempDate, 1);
            timeArray.add(DateTimeUtil.getDateTime(tempDate, "yyyy-MM"));
        }


        endtime = endtime.replaceAll("-", "").substring(0, 6);
        starttime = starttime.replaceAll("-", "").substring(0, 6);



        JSONArray zgArray = new JSONArray();
        JSONArray jmArray = new JSONArray();
        List<Object> list = largeScreenRepository.queryAmount(starttime, endtime, zhlb);
        log.info("queryAmount: {}", list);
        for (int i = 0; i < list.size(); i++) {
            Object o = list.get(i);
            Object[] arr = (Object[]) o;

            String CJT100 = arr[1].toString().trim();
            String AKB068 = arr[2].toString();

            if("居民".equals(CJT100)) {
                jmArray.add(AKB068);
            }
            if("职工".equals(CJT100)) {
                zgArray.add(AKB068);
            }

        }
        JSONObject obj = new JSONObject();
        obj.put("monthArray", timeArray);
        obj.put("jmArray", jmArray);
        obj.put("zgArray", zgArray);
        return obj;

    }
}
